package com.qf.utils.http;

import com.qf.common.configure.HttpClientConfig;
import com.qf.common.configure.ProxyInfo;
import com.qf.common.utils.HttpClientUtil;
import org.apache.http.NameValuePair;

import java.util.List;
import java.util.concurrent.Callable;

public class HttpCallPost implements Callable<String> {
    private String url;
    private List<NameValuePair> list;

    public HttpCallPost(String url, List<NameValuePair> list) {
        this.url = url;
        this.list = list;
    }

    @Override
    public String call() {
        ProxyInfo pi = new ProxyInfo();
//        pi.setTimeout(50000);
        HttpClientConfig config = new HttpClientConfig(pi, url, null, true);
        config.setNvpsList(list);
        config.setTIME_OUT(6000);
        String html = HttpClientUtil.post(config);
        return html;
    }

//    CloseableHttpClient client = HttpClients.custom().build();
//    HttpPost httpPost = new HttpPost(url);
//    // 使用URL实体转换工具
//    UrlEncodedFormEntity urlEntity = null;
//        try {
//        urlEntity = new UrlEncodedFormEntity(list, "UTF-8");
//    } catch (UnsupportedEncodingException e) {
//        e.printStackTrace();
//    }
//        httpPost.setEntity(urlEntity);
//    RequestConfig requestConfig = RequestConfig.custom()
//            .setSocketTimeout(50000).setConnectTimeout(50000).setRedirectsEnabled(true).build();
//        httpPost.setConfig(requestConfig);
//    CloseableHttpResponse response = null;
//    HttpEntity entity = null;
//    String html = "";
//        try {
//        response = client.execute(httpPost);
//        entity = response.getEntity();
//        html = EntityUtils.toString(entity,"utf-8");
//    } catch (IOException e) {
//        e.printStackTrace();
//    }finally {
//        try {
//            EntityUtils.consume(entity);
//            if(response!=null){
//                response.close();
//            }
//            client.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
}


